﻿/*-------------------------------------------------------------------------
* 命名空间: WaferSelectV3.Common/DateTimeHelper
* 类       名: DateTimeHelper
* 功      能:  获取跟日期相关的类
* 时      间:  2024-05-06 9:01:47
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WaferSelectV3.Common
{
    public class DateTimeHelper
    {

        public static Dictionary<DayOfWeek, string> WeekChineseMap = new Dictionary<DayOfWeek, string>()
        {
            { DayOfWeek.Monday,"星期一"},
            { DayOfWeek.Tuesday,"星期二"},
            { DayOfWeek.Wednesday,"星期三"},
            { DayOfWeek.Thursday,"星期四"},
            { DayOfWeek.Friday,"星期五"},
            { DayOfWeek.Saturday,"星期六"},
            { DayOfWeek.Sunday,"星期天"},
        };

        /// <summary>
        ///  获取当前时间的字符串,主要用来回复消息的时候使用.
        ///  中间没有空格和下划线. 
        ///  这种风格: 20230714102054
        /// </summary>
        /// <returns></returns>
        public static string GetDateTimeNowStr()
        {
            return DateTime.Now.ToString("yyyyMMddHHmmssfff");
        }

        /// <summary>
        /// 获取20240223这种保存晶棒汇总的目录
        /// </summary>
        /// <returns></returns>
        public static string GetDateTimeForSummaryDir()
        {
            return DateTime.Now.ToString("yyyyMMdd");
        }
        /// <summary>
        /// 获取当前时间,用于在数据库中显示.
        /// 这种风格 2024-07-14 10:20:54
        /// </summary>
        /// <returns></returns>
        public static string GetTimeNowForSql()
        {
            return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        /// <summary>
        /// 获取年月日,类似2024-05-09 这种
        /// </summary>
        /// <returns></returns>
        public static string GetYearMothDayFull()
        {
            return DateTime.Now.ToString("yyyy-MM-dd");
        }

        /// <summary>
        /// 获取生产日期 2024年05月06日 白班(08:00-20-00)类似这种日期
        /// </summary>
        /// <returns></returns>
        public static string GetProductionDateTime()
        {
            TimeSpan startTime = new TimeSpan(8, 0, 0);
            TimeSpan endTime = new TimeSpan(20, 0, 0);
            DateTime nowTime = DateTime.Now;
            // 获取时间部分,就是时分秒,类似上面的new TimeSpan(8,0,0);
            TimeSpan time = nowTime.TimeOfDay;
            if (time >= startTime && time <= endTime)
            {
                return nowTime.ToString("yyyy年MM月dd日" + " 白班(08:00-20:00)");
            }
            else
            {
                return nowTime.ToString("yyyy年MM月dd日" + "夜班(20:00-08:00)");
            }
        }

        /// <summary>
        /// 2023年06月25日 星期六 14:20:21 类似这种日期显示
        /// </summary>
        /// <returns></returns>
        public static string GetUiShowDateTime()
        {
            DateTime datetime = DateTime.Now;
            // 星期映射,因为这里得到的星期几,是英文的,要把英文的转换为中文的,做了一个映射即可.
            var weekDay = WeekChineseMap[datetime.DayOfWeek];
            return datetime.ToString($"yyyy年MM月dd日 {weekDay} HH:mm:ss");
        }
    }
}
